package com.sneakxy.beetl;

import java.io.FileNotFoundException;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.beetl.core.exception.BeetlException;

public class TemplateFile {

	private String key;
	
	private String name;
	
	private TemplateDir dir;
	
	private ActionTemplate template;
	
	public TemplateFile() {}
	
	public TemplateFile(ActionTemplate template, String key, String name, TemplateDir dir) {
		this.template = template;
		this.key = key;
		this.name = name;
		this.dir = dir;
	}

	public void write(Map<String, Object> params) throws BeetlException, FileNotFoundException {
		String key = StringUtils.join(getDir().getKey(), "/", getKey());
		String out = StringUtils.join(getDir().getPath(), getName());
		System.out.println(String.format("创建文件：%s", out));
		this.getTemplate().write(key, params, out); ; 
	}
	
	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public TemplateDir getDir() {
		return dir;
	}

	public void setDir(TemplateDir dir) {
		this.dir = dir;
	}

	public ActionTemplate getTemplate() {
		return template;
	}

	public void setTemplate(ActionTemplate template) {
		this.template = template;
	}
	
}
